package com.bibrApp.difu.actvity.df_u_mvp;

import android.content.Context;

import com.bibrApp.difu.base.BasePresenter;

public class UPresenter extends BasePresenter<IUView> {
    public UPresenter(Context context, IUView iView) {
        super(context, iView);
    }

    /**
     * 检测账户是否在老平台注册，第一次登录新的币币平台，是则需要用户重置密码
     * 暂时不检查
     *
     * @param map
     */
    /*public void checkLogin(Map<String, String> map) {
        RetrofitNet.getInstance().getApi()
                .checkAccountOfLogin(map)
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(o -> {
                    if (o != null) {
                        if (o.getCode() == 200) {

                        }
                    }
                    Log.d("dj", "========" + o.toString());
                }, throwable -> {
                    Log.d("dj", "异常");
                });

    }

    public void loginT(Map<String, String> map) {
        DialogUtils.showDialog(context);
        RetrofitNet.getInstance().getApi()
                .login(map)
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .subscribe(object -> {
                    if (object != null) {
                        DialogUtils.dismissDialog();
                        String jsonStr = EncryptUtils.objectToJson(object);

                        JsonObject o = new JsonParser().parse(jsonStr).getAsJsonObject();

                        if (o.get("code").getAsInt() == 200) {
                            LoginResponseBody loginRes = new Gson().fromJson(jsonStr, LoginResponseBody.class);
                            if (loginRes != null) {
                                iView.success(loginRes.getData());
                            }
                        } else if (o.get("code").getAsInt() == 500) {
                            iView.error(o.get("message").getAsString());
                        } else {
                            iView.successOfLoginCode(o.get("code").getAsInt(), o.get("data").getAsString());
                        }
                    }
                }, throwable -> {
                    DialogUtils.dismissDialog();
                    iView.error("登录失败");
                    Log.d("dj", throwable.getMessage());
                });

    }

    public void loginOfVerifyCodeT(Map<String, String> map) {
        DialogUtils.showDialog(context);
        RetrofitNet.getInstance().getApi()
                .loginOfVerifyCode( map)
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .subscribe(o -> {
                    DialogUtils.dismissDialog();
                    if (o != null) {
                        if (o.getCode() == 200) {
                            if (o.getData() != null) {
                                iView.success(o.getData());
                                Log.d("dj", "=====" + o.getData());
                            }
                        } else if (o.getCode() == 500) {
                            iView.error(o.getMessage());
                        } else {
                            iView.successOfCode(o.getCode());
                        }
                    }
                }, throwable -> {
                    DialogUtils.dismissDialog();
                    iView.error("登录失败");
                    Log.d("dj", throwable.getMessage());
                });

    }

    *//**
     * 获取验证码
     *
     * @param account
     *//*
    public void getCode(Map<String, String> account) {
        DialogUtils.showDialog(context);
        RetrofitNet.getInstance().getApi()
                .getVerifyCode(account)
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .subscribe(o -> {
                    DialogUtils.dismissDialog();
                    if (o != null) {
                        String msg = TextUtils.isEmpty(o.getData()) ? o.getMessage() : o.getData();
                        if (o.getCode() == 200) {
                            iView.success(msg);
                        } else {
                            iView.error(msg);
                        }
                    }
                }, throwable -> {
                    DialogUtils.dismissDialog();
                    iView.error("获取验证码超时");
                });

    }*/
}
